import java.util.Arrays;
import java.util.Comparator;

public class CustomSortingExample {
    public static void main(String[] args) {
        String[] fruits = {"Apple", "Orange", "Banana", "Mango"};

        // 使用自定义的Comparator对象进行排序
        Arrays.sort(fruits, new LengthComparator());

        // 输出排序后的水果数组
        for (String fruit : fruits) {
            System.out.println(fruit);
        }
    }

    // 自定义的Comparator对象，根据字符串长度进行比较
    static class LengthComparator implements Comparator<String> {
        @Override
        public int compare(String s1, String s2) {
            return s1.length() - s2.length();
        }
    }
}
